﻿using Application.CodeRuleService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.sys;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DictTypeService
{
    public class DictTypeService : IDictTypeService
    {
        private readonly IDictTypeRepository dictTypeRepository;
        private readonly IMapper mapper;

        public DictTypeService(IDictTypeRepository dictTypeRepository,IMapper mapper)
        {
            this.dictTypeRepository = dictTypeRepository;
            this.mapper = mapper;
        }

        //添加字典类型信息
        public async Task<int> AddDictType(AddDictTypeDto addDictTypeDto)
        {
            //转换
            DictType dictType = mapper.Map<DictType>(addDictTypeDto);
            return await dictTypeRepository.AddDictType(dictType);
        }

        //删除字典类型信息
        public async Task<int> DeleteDictType(int id)
        {
            return await dictTypeRepository.DeleteDictType(id);
        }


        //分页查询字典类型信息
        public async Task<FenYe<DictType>> GetDictType(FenYe<DictType> fenYe, string? name, int? status, string? createname, string? starttime, string? endtime)
        {
            return await dictTypeRepository.GetDictType(fenYe, name, status, createname, starttime, endtime);
        }


        //根据id查询字典类型信息
        public async Task<DictType> GetDictTypeById(int id)
        {
            return await dictTypeRepository.GetDictTypeById(id);
        }


        //修改字典类型信息
        public async Task<int> UPdateDictType(UpdateDictTypeDto updateDictTypeDto)
        {
            //转换
            DictType dictType = mapper.Map<DictType>(updateDictTypeDto);
            return await dictTypeRepository.UPdateDictType(dictType);
        }

        //查询所有字典类型
        public async Task<List<DictType>> GetType()
        {
            return await dictTypeRepository.GetType();
        }
    }
}
